package com.cashmate.struts;

import com.cashmate.hibernate.dao.LoanapplicationDAO;
import com.cashmate.hibernate.pojo.Loanapplications;
import com.cashmate.hibernate.pojo.Documents;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;


import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

public class EditLoanapp extends ActionSupport {

    private LoanapplicationDAO loanappDAO = (LoanapplicationDAO) ServletActionContext.getServletContext().getAttribute("loanapplicationDAO");
   // private LoansDAO loanDAO = (LoansDAO) ServletActionContext.getServletContext().getAttribute("loansDAO");
//  private String releasedate;
//  private int suggestedamount;
//  private String firstlast;
//  private String secondlast;
    private String releasedate;
    private String remarks;
    private String amortizationindays;
    private String suggestedamount;
    private String amountrequested;
    private String status;
    private String coborrowerreligion;
    private String coborrowerpostalcode;
    private String coborrowerprovince;
    private String coborrowercityormunicipality;
    private String coborrowerstreetaddress;
    private String coborrowerbarangay;
    private String coborrowermiddlename;
    private String coborrowerlastname;
    private String spouseprovincialpostalcode;
    private String coborrowerfirstname;
    private String spouseprovincialcityormunicipality;
    private String spouseprovincialprovince;
    private String spouseprovincialstreetaddress;
    private String spouseprovincialbarangay;
    private String spousereligion;
    private String spousecitizenship;
    private String spousedateofbirth;
    private String spouseplaceofbirth;
    private String spousemiddlename;
    private String spouselastname;
    private String spousefirstname;
    private String provincialaddresslengthofstayinyears;
    private String provincialaddresslengthofstayinmonths;
    private String presentaddresslengthofstayinmonths;
    private String provincialaddressstatus;
    private String presentaddressstatus;
    private String presentaddresslengthofstayinyears;
    private String provincialprovince;
    private String provincialpostalcode;
    private String provincialcityormunicipality;
    private String provincialstreetaddress;
    private String provincialbarangay;
    private String presentprovince;
    private String presentpostalcode;
    private String presentbarangay;
    private String presentcityormunicipality;
    private String applicationdate;
    private String presentstreetaddress;
    private String documentno;
    private String oper;
    private int id;
    private String loc;

    @Actions({
        @Action(value = "/edit-loanapp", results = {
            @Result(location = "${loc}", name = "success"),
            @Result(location = "${loc}", name = "input")
        })
    })
    @Override
    public String execute() throws Exception {
        loc = "../../loanapplication.jsp?cat=gridappl";
//        if (releasedate != null) {
//            Loanapplications la = loanappDAO.getById(id);
//            la.setReleasedate(releasedate);
//            loanappDAO.update(la);
//        }
//
//        if (firstlast != null) {
//            Loanapplications la = loanappDAO.getById(id);
//            if (la.getFirstlastpn() > 0) {
//                Loans loan = la.getBorrowers().getFirstlast();
//                loan.setModeofpayment(firstlast);
//                loanDAO.update(loan);
//            }
//
//        }
//
//        if (secondlast != null) {
//            Loanapplications la = loanappDAO.getById(id);
//            if (la.getSecondlastpn() > 0) {
//                Loans loan = la.getBorrowers().getSecondlast();
//                loan.setModeofpayment(secondlast);
//                loanDAO.update(loan);
//            }
//        }
//
//        if (suggestedamount > 0) {
//            Loanapplications la = loanappDAO.getById(id);
//            la.setSuggestedamount(suggestedamount);
//            loanappDAO.update(la);
//        }

        if (releasedate != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setReleasedate(releasedate);
            l.setStatus("preapproved");
            loanappDAO.update(l);
        }

        if (remarks != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setRemarks(remarks);
            loanappDAO.update(l);
        }

        if (amortizationindays != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setAmortizationindays(Integer.parseInt(amortizationindays));
            loanappDAO.update(l);
        }

        if (suggestedamount != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSuggestedamount(Integer.parseInt(suggestedamount));
            loanappDAO.update(l);
        }

        if (amountrequested != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setAmountrequested(Integer.parseInt(amountrequested));
            loanappDAO.update(l);
        }

        if (applicationdate != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setApplicationdate(applicationdate);
            loanappDAO.update(l);
        }

        if (documentno != null) {
            Loanapplications l = loanappDAO.get(id);
            Documents d = l.getDocuments();
            d.setDocumentno(documentno);
            l.setDocuments(d);
            loanappDAO.update(l);
        }

        if (spousedateofbirth != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setApplicationdate(spousedateofbirth);
            loanappDAO.update(l);
        }

        if (presentstreetaddress != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentstreetaddress(presentstreetaddress);
            loanappDAO.update(l);
        }
        if (presentbarangay != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentbarangay(presentbarangay);
            loanappDAO.update(l);
        }
        if (presentcityormunicipality != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentcityormunicipality(presentcityormunicipality);
            loanappDAO.update(l);
        }
        if (presentprovince != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentprovince(presentprovince);
            loanappDAO.update(l);
        }
        if (presentpostalcode != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentpostalcode(presentpostalcode);
            loanappDAO.update(l);
        }
        if (provincialstreetaddress != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialstreetaddress(provincialstreetaddress);
            loanappDAO.update(l);
        }
        if (provincialbarangay != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialbarangay(provincialbarangay);
            loanappDAO.update(l);
        }
        if (provincialcityormunicipality != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialcityormunicipality(provincialcityormunicipality);
            loanappDAO.update(l);
        }
        if (provincialprovince != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialprovince(provincialprovince);
            loanappDAO.update(l);
        }
        if (provincialpostalcode != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialpostalcode(provincialpostalcode);
            loanappDAO.update(l);
        }
        if (presentaddressstatus != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentaddressstatus(presentaddressstatus);
            loanappDAO.update(l);
        }
        if (presentaddresslengthofstayinyears != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentaddresslengthofstayinyears(Integer.parseInt(presentaddresslengthofstayinyears));
            loanappDAO.update(l);
        }
        if (presentaddresslengthofstayinmonths != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setPresentaddresslengthofstayinmonths(Integer.parseInt(presentaddresslengthofstayinmonths));
            loanappDAO.update(l);
        }
        if (provincialaddressstatus != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialaddressstatus(provincialaddressstatus);
            loanappDAO.update(l);
        }
        if (provincialaddresslengthofstayinyears != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialaddresslengthofstayinyears(Integer.parseInt(provincialaddresslengthofstayinyears));
            loanappDAO.update(l);
        }
        if (provincialaddresslengthofstayinmonths != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialaddresslengthofstayinmonths(Integer.parseInt(provincialaddresslengthofstayinmonths));
            loanappDAO.update(l);
        }
        if (spousefirstname != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpousefirstname(spousefirstname);
            loanappDAO.update(l);
        }
        if (spousemiddlename != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpousemiddlename(spousemiddlename);
            loanappDAO.update(l);
        }
        if (spouselastname != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpouselastname(spouselastname);
            loanappDAO.update(l);
        }
        if (spouseplaceofbirth != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpouseplaceofbirth(spouseplaceofbirth);
            loanappDAO.update(l);
        }
        if (spousereligion != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpousereligion(spousereligion);
            loanappDAO.update(l);
        }
        if (spousecitizenship != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpousecitizenship(spousecitizenship);
            loanappDAO.update(l);
        }
        if (spouseprovincialstreetaddress != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpouseprovincialstreetaddress(spouseprovincialstreetaddress);
            loanappDAO.update(l);
        }
        if (spouseprovincialbarangay != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpouseprovincialbarangay(spouseprovincialbarangay);
            loanappDAO.update(l);
        }
        if (spouseprovincialcityormunicipality != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setProvincialcityormunicipality(provincialcityormunicipality);
            loanappDAO.update(l);
        }
        if (spouseprovincialprovince != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpouseprovincialprovince(spouseprovincialprovince);
            loanappDAO.update(l);
        }
        if (spouseprovincialpostalcode != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setSpouseprovincialpostalcode(spouseprovincialpostalcode);
            loanappDAO.update(l);
        }
        if (coborrowerfirstname != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowerfirstname(coborrowerfirstname);
            loanappDAO.update(l);
        }
        if (coborrowermiddlename != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowermiddlename(coborrowermiddlename);
            loanappDAO.update(l);
        }
        if (coborrowerlastname != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowerlastname(coborrowerlastname);
            loanappDAO.update(l);
        }
        if (coborrowerstreetaddress != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowerstreetaddress(coborrowerstreetaddress);
            loanappDAO.update(l);
        }
        if (coborrowerbarangay != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowerbarangay(coborrowerbarangay);
            loanappDAO.update(l);
        }
        if (coborrowercityormunicipality != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowercityormunicipality(coborrowercityormunicipality);
            loanappDAO.update(l);
        }
        if (coborrowerprovince != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowerprovince(coborrowerprovince);
            loanappDAO.update(l);
        }
        if (coborrowerpostalcode != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowerpostalcode(coborrowerpostalcode);
            loanappDAO.update(l);
        }
        if (coborrowerreligion != null) {
            Loanapplications l = loanappDAO.get(id);
            l.setCoborrowerreligion(coborrowerreligion);
            loanappDAO.update(l);
        }

        return NONE;
    }

    public void setOper(String oper) {
        this.oper = oper;
    }

    public void setReleasedate(String releasedate) {
        this.releasedate = releasedate;
    }

    public void setAmortizationindays(String amortizationindays) {
        this.amortizationindays = amortizationindays;
    }

    public void setAmountrequested(String amountrequested) {
        this.amountrequested = amountrequested;
    }

    public void setApplicationdate(String applicationdate) {
        this.applicationdate = applicationdate;
    }

    public void setCoborrowerbarangay(String coborrowerbarangay) {
        this.coborrowerbarangay = coborrowerbarangay;
    }

    public void setCoborrowercityormunicipality(String coborrowercityormunicipality) {
        this.coborrowercityormunicipality = coborrowercityormunicipality;
    }

    public void setCoborrowerfirstname(String coborrowerfirstname) {
        this.coborrowerfirstname = coborrowerfirstname;
    }

    public void setCoborrowerlastname(String coborrowerlastname) {
        this.coborrowerlastname = coborrowerlastname;
    }

    public void setCoborrowermiddlename(String coborrowermiddlename) {
        this.coborrowermiddlename = coborrowermiddlename;
    }

    public void setCoborrowerpostalcode(String coborrowerpostalcode) {
        this.coborrowerpostalcode = coborrowerpostalcode;
    }

    public void setCoborrowerprovince(String coborrowerprovince) {
        this.coborrowerprovince = coborrowerprovince;
    }

    public void setCoborrowerreligion(String coborrowerreligion) {
        this.coborrowerreligion = coborrowerreligion;
    }

    public void setCoborrowerstreetaddress(String coborrowerstreetaddress) {
        this.coborrowerstreetaddress = coborrowerstreetaddress;
    }

    public void setDocumentno(String documentno) {
        this.documentno = documentno;
    }

    public void setPresentaddresslengthofstayinmonths(String presentaddresslengthofstayinmonths) {
        this.presentaddresslengthofstayinmonths = presentaddresslengthofstayinmonths;
    }

    public void setPresentaddresslengthofstayinyears(String presentaddresslengthofstayinyears) {
        this.presentaddresslengthofstayinyears = presentaddresslengthofstayinyears;
    }

    public void setPresentaddressstatus(String presentaddressstatus) {
        this.presentaddressstatus = presentaddressstatus;
    }

    public void setPresentbarangay(String presentbarangay) {
        this.presentbarangay = presentbarangay;
    }

    public void setPresentcityormunicipality(String presentcityormunicipality) {
        this.presentcityormunicipality = presentcityormunicipality;
    }

    public void setPresentpostalcode(String presentpostalcode) {
        this.presentpostalcode = presentpostalcode;
    }

    public void setPresentprovince(String presentprovince) {
        this.presentprovince = presentprovince;
    }

    public void setPresentstreetaddress(String presentstreetaddress) {
        this.presentstreetaddress = presentstreetaddress;
    }

    public void setProvincialaddresslengthofstayinmonths(String provincialaddresslengthofstayinmonths) {
        this.provincialaddresslengthofstayinmonths = provincialaddresslengthofstayinmonths;
    }

    public void setProvincialaddresslengthofstayinyears(String provincialaddresslengthofstayinyears) {
        this.provincialaddresslengthofstayinyears = provincialaddresslengthofstayinyears;
    }

    public void setProvincialaddressstatus(String provincialaddressstatus) {
        this.provincialaddressstatus = provincialaddressstatus;
    }

    public void setProvincialbarangay(String provincialbarangay) {
        this.provincialbarangay = provincialbarangay;
    }

    public void setProvincialcityormunicipality(String provincialcityormunicipality) {
        this.provincialcityormunicipality = provincialcityormunicipality;
    }

    public void setProvincialpostalcode(String provincialpostalcode) {
        this.provincialpostalcode = provincialpostalcode;
    }

    public void setProvincialprovince(String provincialprovince) {
        this.provincialprovince = provincialprovince;
    }

    public void setProvincialstreetaddress(String provincialstreetaddress) {
        this.provincialstreetaddress = provincialstreetaddress;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public void setSpousecitizenship(String spousecitizenship) {
        this.spousecitizenship = spousecitizenship;
    }

    public void setSpousedateofbirth(String spousedateofbirth) {
        this.spousedateofbirth = spousedateofbirth;
    }

    public void setSpousefirstname(String spousefirstname) {
        this.spousefirstname = spousefirstname;
    }

    public void setSpouselastname(String spouselastname) {
        this.spouselastname = spouselastname;
    }

    public void setSpousemiddlename(String spousemiddlename) {
        this.spousemiddlename = spousemiddlename;
    }

    public void setSpouseplaceofbirth(String spouseplaceofbirth) {
        this.spouseplaceofbirth = spouseplaceofbirth;
    }

    public void setSpouseprovincialbarangay(String spouseprovincialbarangay) {
        this.spouseprovincialbarangay = spouseprovincialbarangay;
    }

    public void setSpouseprovincialcityormunicipality(String spouseprovincialcityormunicipality) {
        this.spouseprovincialcityormunicipality = spouseprovincialcityormunicipality;
    }

    public void setSpouseprovincialpostalcode(String spouseprovincialpostalcode) {
        this.spouseprovincialpostalcode = spouseprovincialpostalcode;
    }

    public void setSpouseprovincialprovince(String spouseprovincialprovince) {
        this.spouseprovincialprovince = spouseprovincialprovince;
    }

    public void setSpouseprovincialstreetaddress(String spouseprovincialstreetaddress) {
        this.spouseprovincialstreetaddress = spouseprovincialstreetaddress;
    }

    public void setSpousereligion(String spousereligion) {
        this.spousereligion = spousereligion;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setSuggestedamount(String suggestedamount) {
        this.suggestedamount = suggestedamount;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLoc() {
        return loc;
    }
}
